<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" customClass="customWidth" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="left">
			<el-form-item label="接待标题" prop="title">
				<el-input v-model="form.title" placeholder="接待标题" maxlength="80" clearable></el-input>
			</el-form-item>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="接待类型" prop="entertainType">
						<sc-select v-model="form.entertainType" :params="{code:'entertainType'}" :apiObj="$API.system.sysDic.getSysDicByCode" clearable filterable style="width: 100%"></sc-select>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="用餐类型" prop="diningType">
						<sc-select v-model="form.diningType" :params="{code:'diningType'}" :apiObj="$API.system.sysDic.getSysDicByCode" clearable filterable style="width: 100%"></sc-select>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="接待时间" prop="entertainTime">
						<el-date-picker v-model="form.entertainTime" placeholder="接待时间" type="date" value-format="YYYY-MM-DD" style="width: 100%;"></el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="接待人数" prop="userCount">
						<el-input v-model="form.userCount" placeholder="接待人数" type="number" clearable>
							<template #append>人</template>
						</el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="接待人" prop="entertainUser">
						<select-user-dialog v-model:accountId="form.entertainUser" :mode="false"/>
					</el-form-item>
				</el-col>
			</el-row>
			<el-form-item label="备注说明">
				<el-input v-model="form.remark" placeholder="备注说明" type="textarea" clearable rows="3" maxlength="380"></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">确 定</el-button>
		</template>
	</el-dialog>

</template>
<script>
import selectUserDialog from "@/views/module/selectUserDialog";
export default {
	emits: ['success', 'closed'],
	components: {
		selectUserDialog,
	},
	data() {
		return {
			visible: false,
			isSaveing: false,
			mode: "add",
			titleMap: {
				add: '创建接待记录对话框',
				edit: '编辑接待记录对话框',
			},
			templates: [],
			form: {
				recordId:'',
				title: '',
				entertainType: '',
				diningType: '',
				entertainTime: '',
				userCount: 0,
				entertainUser: '',
				remark:'',
				status:'0'
			},
			rules: {
				title: [
					{required: true, message: '接待标题不能为空', trigger: 'blur'}
				],
				userCount: [
					{required: true, message: '接待人数不能为空', trigger: 'blur'}
				],
				entertainTime: [
					{required: true, message: '接待时间不能为空', trigger: 'blur'}
				],
				entertainType: [
					{required: true, message: '接待类型不能为空', trigger: 'blur'}
				],
				diningType: [
					{required: true, message: '用餐类型不能为空', trigger: 'blur'}
				]
			}
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res;
					if (this.mode == "add") {
						res = await this.$API.office.entertain.insertEntertain.post(this.form);
					} else if (this.mode == "edit") {
						res = await this.$API.office.entertain.updateEntertain.post(this.form);
					}
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		setData(data) {
			this.form.recordId = data.recordId
			this.form.title = data.title
			this.form.entertainType = data.entertainType
			this.form.diningType = data.diningType
			this.form.entertainTime = data.entertainTime
			this.form.userCount = data.userCount
			this.form.entertainUser = data.entertainUser
			this.form.remark = data.remark
		},
	}
}
</script>

<style>
.customWidth {
	width: 60%;
}
</style>
